<template>
  <div>
    
    <div class="chain-link-bar-wrapper">
  		<el-breadcrumb separator-class="el-icon-arrow-right">
	  		<el-breadcrumb-item>采购管理</el-breadcrumb-item>
	  		<el-breadcrumb-item to="/procurement/pushList">推送记录</el-breadcrumb-item>
	  	</el-breadcrumb>  
	  </div>

  

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>推送记录</span>
      </div>

      <div class="app-diliver-10"></div>

      <div>
        <div class="app-display-inline app-margin-h-20">
          <span class="color-black-second font-size-text">关键字：</span>
          <el-input
            clearable
            placeholder="产品名、公司名、联系人手机"
            v-model="page.keyWord"
            style="width: 380px;"
              ></el-input>
        </div>

        <div class="app-display-inline app-margin-h-20">
          <SubmitButton
            type="primary" 
            plain
            icon="el-icon-search"
            :post-option="{
              url: searchUrl,
              data: page,
              callback: searchCB
            }"
            >搜索</SubmitButton>
        </div>
      </div>

      <div class="app-diliver-15"></div>
      <div class="app-diliver-15"></div>
      
      <el-table :data="procurementList" stripe border style="width: 100%" @sort-change="sortMethod" class="nc-table-btn-ctrl">
        <el-table-column type="index" :index="indexMethod">
        </el-table-column>
        
        <el-table-column
          label="公司"
          width="200">
          <template slot-scope="scope">
            <span>{{scope.row.company_name}}</span>
            <br>
            <span>{{scope.row.address}}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="联系人"
          width="150">
          <template slot-scope="scope">
            <span>{{scope.row.contact_name}}</span>
            <br>
            <span>{{scope.row.contact_phone}}</span>
            <span v-if="scope.row.contact_email != ''">&nbsp;|&nbsp;{{scope.row.contact_email}}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="产品"
          width="250">
          <template slot-scope="scope">
            <span class="text-bold">{{scope.row.product_name}}</span>
            <br>
            <span>{{scope.row.product_description}}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="数量">
          <template slot-scope="scope">
            <span>{{scope.row.buy_number}}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="有效日期"
          sortable="custom"
          prop="is_time_out_time"
          >
          <template slot-scope="scope">
            <span>{{scope.row.start_date_time_str}}</span>
            <br>~<br>
            <span>{{scope.row.end_date_time_str}}</span>
          </template>
        </el-table-column>
        
        <el-table-column
          label="发布日期"
          sortable="custom"
          prop="add_date_time_str">
        </el-table-column>

        <el-table-column
          prop="is_time_out"
          sortable="custom"
          label="有效状态">
          <template slot-scope="scope">
            <span class="text-bold color-danger" v-if="scope.row.is_time_out == 1">已结束</span>
            <span class="text-bold color-success" v-if="scope.row.is_time_out == 0">未结束</span>
          </template>
        </el-table-column>

        <el-table-column
          label="推送时间"
          sortable="custom"
          prop="createTimeStr"
          >
        </el-table-column>        

        <el-table-column
          label="推送人数"
          prop="pushCnt">
        </el-table-column>

        <el-table-column
          label="操作"
          >
          <template slot-scope="scope">
            <NcButton
              size="mini"
              type="primary"
              :post-option="{url: recallPushUrl, callback: getPage, confirm: '确定要推送采购信息【'+ scope.row.product_name +'】吗？', data: {id: scope.row.id} }"
              class="app-margin-l-10 app-margin-v-5"
              >撤回</NcButton>

            <a class="" :href="'#/procurement/detail/' + scope.row.id" target="_blank">
              <el-button
              plain 
              size="mini" 
              >采购详情</el-button>
            </a>
          </template>
        </el-table-column>
      </el-table>


      <div class="pager-bar-wrapper">
        <el-pagination
          background
          layout="prev, pager, next, total"
          :total="page.totalRow"
          :page-size="page.pageSize"
          :current-page="page.pageNum"
          @current-change="pageNumChange"
          @prev-click="pageNumChange"
          @next-click="pageNumChange"
          @size-change="pageSizeChange"
          >
        </el-pagination>
      </div>

    </el-card>	

  </div>
</template>


<script>

  import NcButton from '../common/NcButton'
  import SubmitButton from '../common/SubmitButton'

  import Api from '../../api/Api'
  import ProcurementApi from '../../api/ProcurementApi'

  import JsonKit from '../../kit/JsonKit'

  import { mapGetters } from 'vuex'

  export default {
  	components: {
  		NcButton, SubmitButton
  	},
  	data(){
  	  return {
  	  	
        procurementList: [],

        page: {
          checkStatus: '',
          keyWord: '',
          pageNum: 1,
          pageSize: 10
        },


        searchUrl: ProcurementApi.URL_PUSH_LIST,
        recallPushUrl: ProcurementApi.URL_RECALL_PUSH,
  	  }
  	},
  	computed: {
  	  ...mapGetters(['hasPerm'])
  	},
  	created(){
  	  this.getPage();

      //this.$root.eventHub.$on('closeEditDialog', this.hideEditDialog);
  	},
    beforeDestroy: function(){
      //this.$root.eventHub.$off('closeEditDialog', this.hideEditDialog);
    },
  	methods: {
  	  sortMethod(column) {
        this.page.columnProp = column.prop;
        this.page.columnOrder = column.order;
        this.getPage();
      },
      searchCB(json){
        this.procurementList = json.list;
        this.setPage(json);
      },
      getPage(){
        ProcurementApi.pushList(this.page, json=>{
          this.procurementList = json.list;
          this.setPage(json);
        });  
      },
      pageNumChange(pageNum){
        this.page.pageNum = pageNum;
        this.getPage();
      },
      pageSizeChange(pageSize){
        this.page.pageSize = pageSize;
        this.getPage();
      },
      setPage(json){
        this.page.pageNum = json.pageNum;
        this.page.pageSize = json.pageSize;
        this.page.totalRow = json.totalRow;
      },
      indexMethod(index){
        return index + 1 + (this.page.pageNum - 1) * this.page.pageSize
      },
  	}
  }
</script>
